package com.lyl.springcloud.controller;

import com.lyl.springcloud.model.Payment;
import com.lyl.springcloud.model.Result;
import com.lyl.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;

/**
 * @author lylbell
 * @date 2021-05-25 15:10
 */
@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {

    @Resource
    PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/create")
    public Result create(@RequestBody Payment payment) {
        int i = paymentService.create(payment);
        if (i > 0) {
            return new Result(200,"数据插入成功",i);
        }else {
            return new Result(444,"数据插入失败",null);
        }
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id) {
        Payment paymenyById = paymentService.getPaymenyById(id);
        System.out.println(paymenyById);
        if (paymenyById != null) {
            return new Result(200,"数据查询成功,serverPort=" + serverPort,paymenyById);
        }else {
            return new Result(444,"数据查询失败" +
                    "，查询ID为" + id,null);
        }
    }

    @GetMapping("/lb")
    public String getServerPort() {
        return this.serverPort;
    }

}
